<%--
    数据库操作页面，操作的结果将转发到userRegisterResult.jsp页面显示
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.dsj.dao.CustomerDao" %>
<%@ page import="com.dsj.entity.CustomerEntity" %>

<!--相当于帮你实例化一个javaBean对象-->
<jsp:useBean id="user" scope="session" class="com.dsj.entity.CustomerEntity"></jsp:useBean>
<jsp:setProperty name="user" property="*"/>

<%
    //获取页面请求参数
    request.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");
    CustomerDao dao = new CustomerDao();
    int action = Integer.parseInt(request.getParameter("action"));
    switch (action) {
        case 0:  //注册用户
            CustomerEntity formSelect = dao.selectCustomerEntity(user.getUserName());
            if (formSelect == null || formSelect.equals("")) {
                if (dao.insertCustomer(user)) {
                    request.setAttribute("registerResult", "新用户注册成功！");
                    session.setAttribute("user", user);
                    session.setAttribute("name", user.getUserName());
                } else {
                    request.setAttribute("registerResult", "新用户注册失败！");
                }
            } else {
                request.setAttribute("registerResult", "该用户已存在！");
            }
%>
            <jsp:forward page="userRegisterResult.jsp"></jsp:forward>
<%
        case 2:  //修改用户信息
            if(dao.updateCustomer(user)) {
                request.setAttribute("userUpdateResult", "用户信息修改成功！");
            } else {
                request.setAttribute("userUpdateResult", "用户信息修改失败！");
            }
%>
            <jsp:forward page="userUpdateResult.jsp"></jsp:forward>
<%
        default:
            break;
    }
%>